package com.lz.ionicbase.view;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.lz.ionicbase.model.WorkListDetailXBean;

import java.util.List;

/**
 * work轮播图整体
 */

public class MyViewPager<T> extends FrameLayout {
    private Context mContext;
    private ViewPager mViewPager;
    private MyWorkPagerAdapter mMyPagerAdapter;
    private MyIndicator mMyIndicator;

    public MyViewPager(Context context) {
        super(context);
        initView(context);
    }
    public MyViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.mContext = context;
        initView(context);
    }

    public MyViewPager(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }
    private void initView(Context context) {
        mViewPager = new ViewPager(context);
        LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        mViewPager.setLayoutParams(layoutParams);
        addView(mViewPager);


        mMyIndicator = new MyIndicator(context);
        LayoutParams inLayoutParams =
                new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        mMyIndicator.setGravity(Gravity.BOTTOM);
        addView(mMyIndicator,inLayoutParams);

        mMyPagerAdapter = new MyWorkPagerAdapter(context,mViewPager);
        mViewPager.setAdapter(mMyPagerAdapter);
    }
    public void setTList(final List<WorkListDetailXBean> list){
        mMyPagerAdapter.setList(list);
        int position = mMyPagerAdapter.getPosition();
        mMyIndicator.init(mContext,position,list.size(), mViewPager);
        List<View> indicatorView = mMyIndicator.getIndicator();
        mMyPagerAdapter.setIndicator(indicatorView);
    }
    public void setCancleHandle(){
        mMyPagerAdapter.cancleHandle();
    }

    public void setStartRoll(){
        mMyPagerAdapter.startRoll();
    }
}
